$(function () {
    layui.use('carousel', function () {
        // 轮播图
        let carousel = layui.carousel
        // 加载轮播图数据
        function loadSwiperList() {
            $.ajax({
                type: 'get',
                url: 'http://59.110.221.161/api/swipers',
                success: function (res) {
                    console.log(res);
                    if (res.status === 0) {
                        let arr = []
                        res.data.forEach(function (item) {
                            arr.push(`
                            <li class="img-effect">
                            <a href="javascript:;">
                            <img src="${'http://59.110.221.161/uploads/' + item.swiperimg}" alt="">
                            </a>
                            </li>
                            `)
                            console.log(item);
                            
                        });
                        $('#kr_carousel ul').html(arr.join(''))
                        // 轮播交互
                         carousel.render({
                         elem: '#kr_carousel',
                         width: 720,
                         height: 300,
                         interval: 3000
                        })
                    }
                    
                }
            })
        }
        loadSwiperList()

        // 友情链接
        function loadLinkList() {
            $.ajax({
                type: 'get',
                url:'http://59.110.221.161/api/links',
                success: function (res) {
                    if (res.status === 0) {
                        let arr = []
                        res.data.forEach(function (item) {
                            arr.push(`
                            <dd>
                             <a href="javascript:;">
                             <img src="${'http://59.110.221.161/uploads/' + item.linkicon}">
                            </a>
                            </dd>
                            `)
                        })
                        $('.kr_collaborator').append(arr.join(''))
                    }
                }
            })
        }
        loadLinkList()
    })
    
})
